package com.app.project;

import java.io.File;
import java.util.Stack;
import java.util.Timer;
import java.util.TimerTask;
import java.util.UUID;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient;
import com.google.android.gms.location.LocationClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.PendingIntent;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {
	
	// -------------Camera----------------------//
	private BluetoothDevice device;
	private static final String Name = "Bluetooth Test";
	private static final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
	private static final int MASSAGE_READ = 100;
	private BluetoothAdapter mBluetoothAdapter = null;
	private BluetoothSocket socket = null;
	private String mDeviceName = "Admin";
	private ListView mDataView;
	private ArrayAdapter<String> mArrayAdapter;
	private StringBuilder sb = new StringBuilder();
	private String Android_Command ="";
	private static final String Speed = "S";
	private static final String Balance = "B";
	private Handler Handler = new Handler();
	
	public Bluetooth_Service Bt = new Bluetooth_Service();
	
	// -------------Camera----------------------//
	private static final int TAKE_PICTURE = 100;
	
	// -------------Map----------------------//
	private LocationClient mLocationclient;
	private Location mCurrentLocation;
	private GoogleMap map;
    private LocationManager locationManager;
    private String provider;
    
    // -------------Monitor----------------------//
    EditText CarID,CarSpeed,CarBalance;
    Button buttonB,buttonS,buttonClear;
    Stack<String> st = new Stack();
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main_map);
		
		map = ((MapFragment) getFragmentManager().findFragmentById(R.id.Map_Map)).getMap();
        map.setMyLocationEnabled(true);
        map.setMapType(GoogleMap.MAP_TYPE_HYBRID);
        
        CarID = (EditText) findViewById(R.id.A_Main_carid);
//	    CarSpeed = (EditText) findViewById(R.id.A_Main_carspeed);
	    CarBalance = (EditText) findViewById(R.id.A_Main_Balance);
	    
	    Bundle bundle = getIntent().getExtras();
		if(bundle != null){
			mDeviceName = (String) bundle.get("Device Name");
		}
		this.setTitle("Connect Car "+ mDeviceName);
		CarID.setText(mDeviceName);
		String address = (String) bundle.get("Device Address");
		
		mBluetoothAdapter= BluetoothAdapter.getDefaultAdapter();
		device = mBluetoothAdapter.getRemoteDevice(address);
		
		mArrayAdapter = new ArrayAdapter<String>(this, R.layout.databluetooth);
		mDataView = (ListView) findViewById(R.id.A_Main_listmessage);
		mDataView.setAdapter(mArrayAdapter);
		
		buttonB = (Button)findViewById(R.id.A_Main_buttonB);
	    buttonB.setOnClickListener(SentCommanB);
		
	}
	
	private OnClickListener SentCommanB = new OnClickListener() {
        public void onClick(View v) {
    		mArrayAdapter.clear();
        	Bt.SentComman("B");
        }
}; 

}
	